/*
 * @Author: 流程控制 break goto continue
 * @Date: 2021-01-21 17:11:35
 * @LastEditTime: 2021-01-21 17:29:44
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \go_demo\src\06_break_goto_continue\main.go
 */
package main

import "fmt"

func main() {
	//continue break
	for i := 1; i <= 10; i++ {
		if i == 3 {
			continue
		} else if i == 8 {
			break
		}

		fmt.Println(i)
	}

    //跳出多重循环，可以用标号 label（可以是任何名称的标号） 标出想break的循环
    /*
    结果：
        i = 0 j = 0
        i = 0 j = 1
        i = 0 j = 2
    */
label:
	for i := 0; i < 2; i++ {
		for j := 0; i < 10; j++ {
			if j == 3 {
				break label
			}
			fmt.Printf("i = %v j = %v \n", i, j)
		}
    }
    
    /*
    跳出子循环，母循环继续
    结果：
        i1 = 0 j1 = 0
        i1 = 0 j1 = 1
        i1 = 0 j1 = 2
        i1 = 1 j1 = 0
        i1 = 1 j1 = 1
        i1 = 1 j1 = 2
    */
label2:
	for i := 0; i < 2; i++ {
		for j := 0; i < 10; j++ {
			if j == 3 {
				continue label2
			}
			fmt.Printf("i1 = %v j1 = %v \n", i, j)
		}
    }
    
    // goto
    var age = 24
    if age > 26 {
        goto a
    } else {
        goto b
    }

    a:
    fmt.Println("aaa")

    b:
    fmt.Println("bbb")
}


